//
//  WarringVC.m
//  MovieDate
//
//  Created by 杨运涛 on 16/4/18.
//  Copyright © 2016年 MovieDate. All rights reserved.
//

#import "WarringVC.h"
#import "WarringContentVC.h"

@interface WarringVC () <UIAlertViewDelegate>

@end

@implementation WarringVC

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)initInfo {
    [super initInfo];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self selAddLeftBackButton];
    [self selDefaultNavigationBackground];
    [self.pTableView setTableFooterView:[UIView new]];
}


#pragma mark - UITableViewDataSource, UITableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 3;
    } else {
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"idfWarringCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"idfWarringCell"];
    }
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"垃圾消息骚扰";
        } else if(indexPath.row == 1) {
            cell.textLabel.text = @"传播色情/暴力/反动等不良信息";
        } else {
            cell.textLabel.text = @"欺诈骗钱";
        }
    } else {
        cell.textLabel.text = @"将对方拉进黑名单";
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        [self performSegueWithIdentifier:@"idfWarringContentVC" sender:nil];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"确认将对方放入黑名单?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alert show];
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.1f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}


#pragma mark - UIAlertViewDelegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        [SVProgressHUD show];
        [TDNetwork requestAddBlackList:setBlackList_interface toUid:_pStrID complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary) {
            [SVProgressHUD showSuccessWithStatus:@"您已将对方加入黑名单中,如想取消,请前往社交的黑名单列表中移除."];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadSeeList" object:nil];
            [self performSelector:@selector(selPopToRootViewController) withObject:nil afterDelay:1.5f];
        }];
    }
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    WarringContentVC *nextVC = segue.destinationViewController;
    nextVC.pStrID = _pStrID;
}


@end
